<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="https://cdn.bootcdn.net/ajax/libs/vue/2.6.14/vue.js"></script>
</head>
<body>
    <div id="app">
        <div v-if="isLoading">
            加载中
        </div>
        <div v-else ref="contentRef">
            <img/>
        </div>
    </div>
</body>
<script>
let vm = new Vue({
    el: '#app',
    data(){
        return {
            isLoading: true
        }
    },
    async mounted() {
        await this.getArticleDetail()
        //修改数据之后,页面渲染是异步的,并且页面渲染是Promise.then,没有立即执行
        this.isLoading = false
        //解决在渲染之后执行代码-方式1-用Promise.then
        /*
        new Promise((resolve,reject)=> resolve()).then(()=>{
            console.log('contentRef',this.$refs.contentRef)
            let imgs = this.$refs.contentRef.querySelectorAll('img')
            console.log(imgs)
        })
        */
       //解决在渲染之后执行代码-方式2-this.$nextTick
       /*
       this.$nextTick(()=>{
            console.log('contentRef',this.$refs.contentRef)
            let imgs = this.$refs.contentRef.querySelectorAll('img')
            console.log(imgs)
       })
       */
       //解决在渲染之后执行代码-方式3-setTimeout
       setTimeout(() => {
            console.log('contentRef',this.$refs.contentRef)
            let imgs = this.$refs.contentRef.querySelectorAll('img')
            console.log(imgs)
       }, 0)
    },
    methods: {
        getArticleDetail(){
            return new Promise((resolve,reject)=>{
                setTimeout(() => {
                    resolve()
                }, 500)
            })
        }
    }
})
</script>
</html>